package com.beiyou.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.beiyou.dao.GoodsMapper;
import com.beiyou.dao.ProductMapper;
import com.beiyou.dto.GoodsDto;
import com.beiyou.dto.GoodsDtoQuery;
import com.beiyou.dto.ProductDto;
import com.beiyou.dto.ProductDtoQuery;
import com.beiyou.entity.GoodsEntity;
import com.beiyou.entity.ProductEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wzby
 * @Date: 2022/10/21 9:58
 */
@Service
public class ProductService {
    @Autowired
    private ProductMapper productMapper;

    public Integer insert(ProductDto productDto){
        ProductEntity productEntity = BeanUtil.copyProperties(productDto, ProductEntity.class);
        return productMapper.insert(productEntity);
    }

    public Integer statusUpdate(Integer id, Integer status){
        return productMapper.statusUpdate(id, status);
    }

    public List<ProductDto> selectXml(ProductDtoQuery productDtoQuery){
        List<ProductEntity> entities = productMapper.selectXml(productDtoQuery);
        return BeanUtil.copyToList(entities,ProductDto.class);
    }

    public Integer update(ProductDto productDto){
        ProductEntity productEntity = BeanUtil.copyProperties(productDto, ProductEntity.class);
        return productMapper.update(productEntity);
    }

//    public List<ProductDto> select(ProductDtoQuery productDtoQuery){
//        LambdaQueryWrapper<ProductEntity> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(productDtoQuery.getGoodsId() != null, ProductEntity::getGoodsId,productDtoQuery.getGoodsId());
//        wrapper.eq(productDtoQuery.getId() != null, ProductEntity::getId,productDtoQuery.getId());
//        wrapper.eq(productDtoQuery.getStatus() != null, ProductEntity::getId,productDtoQuery.getStatus());
//        wrapper.eq(productDtoQuery.getName() != null, ProductEntity::getId,productDtoQuery.getName());
//        List<ProductEntity> productEntityList = productMapper.selectList(wrapper);
//        List<ProductDto> productDto = BeanUtil.copyToList(productEntityList, ProductDto.class);
//        return productDto;
//    }
}
